#include "base_belt.h"

#ifndef HEAD_Q_H
#include "../../head_Q.h"
#endif

Base_Belt::Base_Belt(Belt_Define * define, FacilityDirection f_dir,Coordinate coordinate,Cargo_Manager * cargo_manager)
    :Facility(define, f_dir,coordinate,cargo_manager){

}
void Base_Belt::finishProcess() {
    this->outcargos[0] = this->incargos[0];
    this->incargos[0] = null;
    sendCargo();
    Facility::finishProcess();
}
void Base_Belt::duringProcess(){
    Cargo *c = this->incargos[0];
    double x = my_x - CARGO_SHOW_LENTH / 2.0, y = my_y - CARGO_SHOW_LENTH / 2.0;
    if(time_record < define->interval / 2.0){
        double dis = define->process_speed * time_record;
        switch(this->abs_enters[0].direction){
        case gate::Gate_UP:
            x = x + BOX_LENTH / 2.0 ;
            y = y + dis;
            break;
        case gate::Gate_RIGHT:
            x = x + BOX_LENTH - dis;
            y = y + BOX_LENTH / 2.0 ;
            break;
        case gate::Gate_DOWN:
            x = x + BOX_LENTH / 2.0;
            y = y + BOX_LENTH - dis;
            break;
        case gate::Gate_LEFT:
            x = x + dis;
            y = y + BOX_LENTH / 2.0;
            break;
        default:
            break;
        }
    }
    else{
        double dis = define->max_interval - define->process_speed * time_record;
        switch(this->abs_exits[0].direction){
        case gate::Gate_UP:
            x = x + BOX_LENTH / 2.0 ;
            y = y + dis;
            break;
        case gate::Gate_RIGHT:
            x = x + BOX_LENTH - dis;
            y = y + BOX_LENTH / 2.0 ;
            break;
        case gate::Gate_DOWN:
            x = x + BOX_LENTH / 2.0;
            y = y + BOX_LENTH - dis;
            break;
        case gate::Gate_LEFT:
            x = x + dis;
            y = y + BOX_LENTH / 2.0;
            break;
        default:
            break;
        }
    }
    c->object_qt->setOffset(x,y);
}
